<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-8-21
 * Time: 上午12:19
 * To change this template use File | Settings | File Templates.
 */
class other extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();

        if ( !$this->AdminIsLogin() ) {
            $this->load->helper('url');
            redirect('/administrator/admin_login/index');
        }
    }

    public function index()
    {
        $this->load->view('administrator/reset_password');
    }

    public function ingot_sent()
    {
        if($this->isPOST())
        {
            $input['passport'] = $this->input->post('passport');
            $input['amount'] = max((int)$this->input->post('amount'),0);
            if(!$input['passport'] || !$input['amount'])
            {
                $this->message('赠送失败', '通行证和元宝数不能为空' , '/administrator/other/ingot_sent');
                return ;
            }

            $this->load->model('user/Model_User', 'user');
            $uInfo = $this->user->getUserInfoByPassport($input['passport'], 'user_id, user_status, is_activation');
            if(!$uInfo || !$uInfo['user_status'] || !$uInfo['is_activation'])
            {
                $this->message('赠送失败', '用户不存在或用户未被激活' , '/administrator/other/ingot_sent');
                return ;
            }

            $input['order_sn'] = 'present_'.date('YmdHis').rand(10000,99999);
            $sign = md5($input['passport'].$input['amount'].$input['order_sn'].config_item('CLIENT_PAY_KEY'));
            $data = array('fillAccount'=>$input['passport'], 'trueMoney'=>$input['amount'], 'fillOrder'=>$input['order_sn'], 'channel'=>config_item('CLIENT_PAY_MARK'), 'sign'=>$sign,);
            $gamePayStatus = @post(config_item('CLIENT_PAY_PATH'), $data);
            //$gamePayStatus = 'iReturn=0&fillAccount=zqhjerry@tom.com&trueMoney=1.00&fillOrder=201151029&sign=1F8A0D40474C96991001217C20E500F7&sMessage=充值成功';
            //var_dump($gamePayStatus);
            if($gamePayStatus)
            {
                parse_str($gamePayStatus, $returnData);
                if($returnData['iReturn'] == '0')
                {
                    $this->load->database();
                    $input['create_time'] = date('Y-m-d H:i:s');
                    $this->db->insert('present', $input['passport']);
                    $this->db->close();
                }
                $this->message($returnData['sMessage'], $returnData['sMessage'] , '/administrator/other/ingot_sent');
            }
            else
            {
                $this->message('赠送失败', '调用接口失败' , '/administrator/other/ingot_sent');
            }

        }
        else
            $this->load->view('administrator/present');
    }

    public function email()
    {
        $this->load->model('model_order', 'order');
        $data = $this->order->getIncome();
        //echo '<pre>';print_r($data);exit;
        $this->load->view('administrator/email', array('data' => $data));
    }
}
